const router = require("koa-router")();
const fs = require("fs");
router.prefix("/home");
const { query } = require("../utils/db");
const { CAMPUSSCENERY_QUERY_SQL } = require("./../utils/sql");
router.get("/getCampusScenery", async (ctx, next) => {
  const res = await query(CAMPUSSCENERY_QUERY_SQL);
  const imgUrls = res.map((item) => item.imgUrl);
  const base64DataArr = [];
  imgUrls.forEach((item) => {
    base64DataArr.push(fs.readFileSync(item, "base64"));
  });
  if (base64DataArr.length === res.length) {
    ctx.body = {
      status: 200,
      msg: "获取校园风光图片成功",
      data: base64DataArr,
    };
  } else {
    ctx.body = {
      status: 500,
      msg: "获取校园风光图片失败",
    };
  }
});
module.exports = router;
